<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户优惠券</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/Coupons/UserCouponList.css">
</head>
<body>
<div class="layui-row">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
        <div class="layui-card headerCenter">
            <div class="layui-card-header backColor">
                优惠券查询
                <div class="btnRight" style="margin-bottom: 10px">
                    <button onclick="refresh()" type="button" class="layui-btn layui-btn layui-btn-sm">
                        <i class="layui-icon layui-icon-refresh-1"></i>
                        刷新
                    </button>
                    <button onclick="backOff()" type="button" class="layui-btn layui-btn layui-btn-sm">
                        <i class="layui-icon layui-icon-return"></i>
                        返回
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--筛选查询-->
<div class="layui-row">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
        <div class="layui-card headerCenter">
            <div class="layui-card-header backColor" style=" font-size: 16px; height: 40px; font-weight: bold;">
                <i class="layui-icon">&#xe615;</i>
                筛选查询
            </div>
            <div class="layui-card-body">
                <form lay-filter="searchForm" class="layui-form" style="margin-top: 5px">
                    <div class="layui-form-item">
                        <div class="fl">
                            <label class="layui-form-label fontsize" >用户账号：</label>
                            <div class="layui-input-inline" style="margin-right: -30px; padding-right: -30px">
                                <input type="text" name="account" required lay-verify="required" placeholder="用户账号" autocomplete="off" class="layui-input inp">
                            </div>
                        </div>

                        <div class="fl">
                            <label class="layui-form-label fontsize" >用户名称：</label>
                            <div class="layui-input-inline" style="margin-right: -30px; padding-right: -30px">
                                <input type="text" name="nickname" required lay-verify="required" placeholder="用户名称" autocomplete="off" class="layui-input inp">
                            </div>
                        </div>

                        <span style="float:right;">
                                    <button onclick="search()" type="button" class="layui-btn layui-btn-sm">
                                        <i class="layui-icon layui-icon-search"></i> 搜索
                                    </button>
                                    <button onclick="getUseCouponData()" type="reset" class="layui-btn layui-btn-warm layui-btn-sm">
                                        <i class="layui-icon layui-icon-refresh-1"></i> 重置
                                    </button>
                                </span>
                    </div>
                </form>
            </div>
        </div>
        <div class="backColor ">
            <div class="backColor" style=" font-size: 16px; height: 40px; font-weight: bold; line-height: 50px; margin: 16px 0 0 20px">
                <i class="layui-icon layui-icon-list"></i>
                数据列表
            </div>
            <!--部门表格-->
            <div>
                <table id="demo" lay-filter="test"></table>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['jquery', 'layer', 'table', 'form', 'upload'], function () {
        $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            upload = layui.upload,
            table = layui.table;


        //获取用户优惠券使用记录表
        $.ajax({
            url:'/CouponUsed/getTable',
            methos:'post',
            dataType:'json',
            success:function (data) {
                tab(data);
            }
        })

        function tab(data) {
            table.render({
                elem: '#demo',
                data: data.data,
                toolbar: true,
                cols: [[
                    {type: 'checkbox'},
                    {field:'userId',title:'用户ID', align:'center'},
                    {field:'account',title:'用户账号',align:'center'},
                    {field:'nickname',title:'用户名称',align:'center'},
                    {field:'',title:'已使用',align:'center',templet:function (data) {
                            var msg;
                            $.ajax({
                                url:'/CouponUsed/getTableByAnUsedState',
                                methos:'post',
                                data:{'userId':data.userId,'usedState':3},
                                dataType:'json',
                                async:false,
                                success:function (data) {
                                    msg = data.data;
                                }
                            })
                            return msg;
                        }},
                    {field:'',title:'未使用',align:'center',templet:function (data) {
                            var msg;
                            $.ajax({
                                url:'/CouponUsed/getTableByAnUsedState',
                                methos:'post',
                                data:{'userId':data.userId,'usedState':2},
                                dataType:'json',
                                async:false,
                                success:function (data) {
                                    msg = data.data;
                                }
                            })
                            return msg;
                        }},
                    {field:'',title:'已过期',align:'center',templet:function (data) {
                            var msg;
                            $.ajax({
                                url:'/CouponUsed/getTableByEndDate',
                                methos:'post',
                                data:{'userId':data.userId},
                                dataType:'json',
                                async:false,
                                success:function (data) {
                                    msg = data.data;
                                }
                            })
                            return msg;
                        }},
                    {title:'操作',align:'center', templet:function(data){
                            return "<span><a onclick='giveUseCouponUsed(" + data.userId  + ")' class='operation'>赠送优惠券</a></span>";
                        }},
                ]]
            });
        }

        //根据条件搜索
        search = function search() {
            var account = $("input[name = account]").val();//用户账号
            var nickname = $("input[name = nickname]").val();//用户昵称
            var selectDate = {
                account : account,
                nickname : nickname
            }
            $.ajax({
                url:'/CouponUsed/queryCouponList',
                dataType:'json',
                data:selectDate,
                success:function (data) {
                    tab(data);
                }
            })
        }

        //刷新
        refresh = function refresh() {
            window.location.reload();
        }

        //赠送优惠券
        giveUseCouponUsed = function giveUseCouponUsed(id) {
            layer.open({
                type: 2,
                maxmin: 'true',
                offset: 'auto',
                resize: false,
                title: '赠送优惠券',
                area: ['1000px', '600px'],
                content:'giveUserCouponList.html'
            });
        }

        //返回首页
        backOff = function backOff(){
            parent.jumpSystemHome();
        }
    })
</script>
</html>